const swaggerJsdoc = require('swagger-jsdoc');

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: '系统管理 API',
      version: '1.0.0',
      description: '系统管理的 API 文档',
    },
    components: {
      schemas: {
        ModelField: {
          type: 'object',
          properties: {
            field: {
              type: 'string',
              description: '字段名称'
            },
            type: {
              type: 'string',
              description: '字段类型',
              enum: ['String', 'Number', 'Boolean', 'Date', 'ObjectId', 'Array']
            },
            required: {
              type: 'boolean',
              description: '是否必填'
            },
            default: {
              type: 'string',
              description: '默认值'
            },
            unique: {
              type: 'boolean',
              description: '是否唯一'
            },
            ref: {
              type: 'string',
              description: '引用的模型名称'
            },
            enum: {
              type: 'array',
              items: {
                type: 'string'
              },
              description: '枚举值列表'
            },
            description: {
              type: 'string',
              description: '字段描述'
            }
          }
        },
        ModelSchema: {
          type: 'object',
          properties: {
            modelName: {
              type: 'string',
              description: '模型名称'
            },
            fields: {
              type: 'array',
              items: {
                $ref: '#/components/schemas/ModelField'
              }
            },
            indexes: {
              type: 'array',
              items: {
                type: 'object'
              },
              description: '索引信息'
            },
            timestamps: {
              type: 'boolean',
              description: '是否启用时间戳'
            }
          }
        },
        ModelList: {
          type: 'object',
          properties: {
            name: {
              type: 'string',
              description: '模型名称'
            },
            collection: {
              type: 'string',
              description: '集合名称'
            }
          }
        },
        UploadToken: {
          type: 'object',
          properties: {
            token: {
              type: 'string',
              description: '上传凭证'
            },
            domain: {
              type: 'string',
              description: '七牛云域名'
            }
          }
        },
        UploadResult: {
          type: 'object',
          properties: {
            url: {
              type: 'string',
              description: '文件访问链接'
            },
            name: {
              type: 'string',
              description: '文件名'
            },
            size: {
              type: 'number',
              description: '文件大小'
            }
          }
        }
      },
      securitySchemes: {
        bearerAuth: {
          type: 'http',
          scheme: 'bearer',
          bearerFormat: 'JWT',
        },
      },
      responses: {
        UnauthorizedError: {
          description: '未授权访问',
          content: {
            'application/json': {
              schema: {
                type: 'object',
                properties: {
                  code: {
                    type: 'number',
                    example: 401
                  },
                  message: {
                    type: 'string',
                    example: '未授权访问'
                  }
                }
              }
            }
          }
        },
        ForbiddenError: {
          description: '没有操作权限',
          content: {
            'application/json': {
              schema: {
                type: 'object',
                properties: {
                  code: {
                    type: 'number',
                    example: 403
                  },
                  message: {
                    type: 'string',
                    example: '没有操作权限'
                  }
                }
              }
            }
          }
        }
      }
    },
    tags: [
      {
        name: 'Dictionary',
        description: '字典管理相关接口'
      },
      {
        name: 'Users',
        description: '用户管理相关接口'
      },
      {
        name: 'Captcha',
        description: '验证码相关接口'
      },
      {
        name: 'Roles',
        description: '角色管理相关接口'
      },
      {
        name: 'Menus',
        description: '菜单管理相关接口'
      },
      {
        name: 'Schema',
        description: '数据库结构相关接口'
      },
      {
        name: 'Upload',
        description: '文件上传相关接口'
      }
    ]
  },
  apis: ['./src/routes/modules/*.js'],
};

module.exports = swaggerJsdoc(options); 